<!-- -*- mode: R -*- -->
  <!--
  ## This program is fre esoftware: you can redistribute it and/or modify
  ## it under the terms of the GNU General Public License as published by
  ## the Free Software Foundation, either version 3 of the License, or
  ## any later version.
  ##
  ## This program is distributed in the hope that it will be useful,
  ## but WITHOUT ANY WARRANTY; without even the implied warranty of
  ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  ## GNU General Public License for more details.
  ##
  ## You should have received a copy of the GNU General Public License
  ## along with this program.  If not, see <http://www.gnu.org/licenses/>.
  -->
  
  <%
setContentType("text/html")
#RApacheOutputErrors(TRUE)
#options(hverbose=FALSE,verbose=FALSE)
%>
  
<html>
<head>
<title>Strategico Online Web Service (Run) on <%=SERVER$hostname%></title>
</head>
<body>
  <center>
<h1><img src="http://www.r-project.org/Rlogo.jpg" />Strategico - Online Service on <%=SERVER$hostname%></h1>
  </center>
  
  <%
strategico.home <- as.character(Sys.getenv("STRATEGICO_HOME"))
source(file.path(strategico.home, "strategico_util.R"))

decimals       <- ifelse(is.null(GET$decimals    ), ".", GET$decimals)
ts             <- ifelse(is.null(GET$ts          ), "0", GET$ts)
period.start   <- ifelse(is.null(GET$period_start), "2000-1", GET$period_start)
period.freq    <- ifelse(is.null(GET$period_freq), "2", GET$period_freq)
eval           <- ifelse(is.null(GET$eval), "ltp", GET$eval)
id             <- ifelse(is.null(GET$id), Item.GetNewID(), as.numeric(GET$id))

if (!decimals==".")
  ts = gsub(decimals, ".", ts)

if (!is.null(GET$thousands))
  ts = gsub(GET$thousands, "", ts)

ts = gsub("\r\n", ",", ts)
ts = gsub("\r", ",", ts)
ts = gsub("\n", ",", ts)
ts = gsub(" ", ",", ts)

#project.name <- paste("web", eval, sep="-")
project.name <- "sample"

output_path = Item.GetUrl(project.name, id=id, value="V1")
db.channel <- NULL
link = file.path(output_path, "report.html")
%>
  INPUT DATA:<br /><br />  
  ts.string=<%=ts%><br />
  period.start=<%=period.start%><br />
  period.freq=<%=period.freq%><br />
  params=<%=GET$params%><br />

  <br /><br /> 
  RUN:<br /><br />  
  <%
if (!is.null(GET$submit)) {
  param <- Param.EvalString(GET$params)
  EvalTSString(project.name=project.name,
               id=id,
               ts.string=ts,
               period.start.string=period.start,
               period.freq=period.freq,
               param=param,
               db.channel=db.channel)
     
  cat(paste("<br /><br />Goto report <a href=\"",
            link,
            "\">page</a> ",
            "(if generated) or <a href=\"",
            output_path,
            "\">folder</a>.",
            sep=""))
} else
cat("no post submit")
%>

<% BrewTemplate('footer') %>

